<?php
class Search_Form_CommercialRefineForm extends Ac_Form
{
    private $settings;
    protected $elementDecorators = array(
        'ViewHelper',
        'Errors',
       // 'Description'
        array('Label', array()),
        //array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class'=>'inputText')),
    );

    protected $elementSelectDecorators = array(
        'ViewHelper',
        'Errors',
       // 'Description'
        array('Label', array()),
        array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class'=>'select')),
    );

    protected $formDecorators = array(
        'FormElements',
  //      array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
        array('Description', array('placement' => 'prepend')),
        'Form',
            
    );

    protected $elementCheckBoxDecorators = array(
        'ViewHelper',
        'Errors',
        // 'Description'
        //array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
        array('Label', array('placement' => 'APPEND')),
        array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class'=>'checkbox')),
    );

    protected $displayGroupDecorators = array(
        'FormElements',
        //array(array('innerHTmlTag' => 'HtmlTag'), array('tag' => 'div', 'class' => 'checkbox'))
        //array('HtmlTag', array('tag' => 'dl')),
    );


    protected $subFormDecorators = array(
        'FormElements',
        array('Description', array('placement' => 'prepend')),
    );


    protected $elementButtonDecorators = array(
        'ViewHelper',
        'Errors',
       // 'Description'
        //array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
        //array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class'=>'button')),
        //array('HtmlTag', array('class' => 'inputText')),
    );

    public function __construct($options = array())
    {
        $this->settings = (object) (!empty($options['settings']) ? $options['settings'] : array());
        parent::__construct($options);
    }

    protected function narrowSearch()
    {
        $form1 = $this->getNewSubForm();

        // Prefered Seller
        $form1->addElement('radio', 'saleby', array(
            //'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                //'Int'
            ),
            'multiOptions' => array(
                'Agency' => 'Agency',
                'Owner' => 'Owner',
            ),
            'separator' => ' ',
            'disableLoadDefaultDecorators' => true,
            'decorators' => $this->elementDecorators,
            'value'      => $this->getSetting('saleby'),
            'required'   => true,
        ));

        $form1->addDecorator('fieldset', array('class' => 'narrow'));
        $form1->setLegend('Sale by');
        $this->addSubForm($form1, 'seller');
    }

    protected function button()
    {
        $form2 = $this->getNewSubForm();
        $form2->setDecorators(
                array('FormElements')
        );
        // Submit Button
        $form2->addElement('button', 'v', array(
            'required'   => false,
            'ignore'     => true,
            'type'       => 'submit',
            'label'      => 'Go!',
            'decorators'  => array(
                    'Errors',
                    'ViewHelper',
                    array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'button')),
            )
        ));

        $this->addSubForm($form2, 'key_search_tools2');
    }

    protected function wantTo()
    {
        $form1 = $this->getNewSubForm();

        // Want to
        $val = $this->getSetting('buy_rent');
        
        if ($val == 'Both') {
            $tmp = $this->getElement('small_category_list')->getValue();
            if (Zend_Registry::isRegistered('category_list_id') && 
                    in_array(Zend_Registry::get('category_list_id'), array('4cda3e818835c16810160000', '4cda3e818835c16810120000', '4cda3e818835c168101b0000'))) {
                
                    $val = 'Buy';
            } elseif (Zend_Registry::isRegistered('category_list_id') && 
                    in_array(Zend_Registry::get('category_list_id'), array('4cda3e818835c16810140000', '4cda3e818835c16810190000', '4cda3e818835c168101a0000'))) {
                    $val = 'Rent';
            }
        }
        
        
        
        // Want to
        $form1->addElement('radio', 'buy_rent', array(
            //'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                //'Int'
            ),
            'multiOptions' => array(
                'Rent' => 'Rent',
                'Buy' => 'Buy',
                'Both' => 'Both',
            ),
            'separator' => ' ',
            'Description' => 'I want to',
            'decorators' => array(
                    'ViewHelper',
                    'Errors',
                    // 'Description'
                    array('Description', array('escape' => false, 'placement' => 'PREPEND', 'tag' => 'span', 'class' => '')),
                    array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class'=>'radio')),
            ),
            'value'      => $val,
            'required'   => true,
        ));
        $form1->getElement('buy_rent')->removeDecorator('label');

        $form1->addDecorator('fieldset', array('class' => 'narrow'));
        $form1->setLegend('Narrow Your Search');
        $this->addSubForm($form1, 'want_to');
    }

    protected function optional()
    {
        $form1 = $this->getNewSubForm();

        // -> Includes management and government fees
        $form1->addElement('checkbox', 'includes_fees', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementCheckBoxDecorators,
            'multiOptions' => array(''=>'All', '1'=>'Yes', '0'=>'No'),
            'required'     => false,
            'label'        => 'Includes Management & government Fees',
            'value'        => $this->getSetting('includes_fees'),
        ));

        // -> Buy with a Lease
        $form1->addElement('checkbox', 'buy_with_lease', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementCheckBoxDecorators,
            'multiOptions' => array(''=>'All', '1'=>'Yes', '0'=>'No'),
            'required'     => false,
            'label'        => 'Buy with a lease',
            'value'        => $this->getSetting('buy_with_lease'),
        ));

        // -> Price negotiable
        $form1->addElement('checkbox', 'price_negotiable', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementCheckBoxDecorators,
            'multiOptions' => array(''=>'All', '1'=>'Yes', '0'=>'No'),
            'required'     => false,
            'label'        => 'Price negotiable',
            'value'        => $this->getSetting('price_negotiable'),
        ));

        // -> Management Fee
        $form1->addElement('jqslider', 'management_fee', array(
                    'jQueryParams' => array(
                        'min'      => $this->getSetting('management_fee_min') !== null ? $this->getSetting('management_fee_min') : Model_Listing_Commercial::MANAGEMENT_FEE_MIN,
                        'max'      => $this->getSetting('management_fee_max') !== null ? $this->getSetting('management_fee_max') : Model_Listing_Commercial::MANAGEMENT_FEE_MAX,
                        'values'   => $this->getSetting('management_fee_start') !== null ? $this->getSetting('management_fee_start') : array(Model_Listing_Commercial::MANAGEMENT_FEE_MIN, Model_Listing_Commercial::MANAGEMENT_FEE_MAX),
                        'currency' => '$HKD',
                        'range'    => true,
                        'step'     => 500,
                        'change'   => 'refineSearch()',
                        ),
                    'label'       => 'Management Fee (HKD)',
                    'decorators' => array(
                            'Errors',
                            'UiWidgetElement',
                            array('Label', array('escape' => false)),
                            array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'slide')),
                    )
                )
        );

        // -> government Fee
        $form1->addElement('jqslider', 'government_fee', array(
                    'jQueryParams' => array(
                        'min'      => $this->getSetting('government_fee_min') !== null ? $this->getSetting('government_fee_min') : Model_Listing_Commercial::GOVERNMENT_FEE_MIN,
                        'max'      => $this->getSetting('government_fee_max') !== null ? $this->getSetting('government_fee_max') : Model_Listing_Commercial::GOVERNMENT_FEE_MAX,
                        'values'   => $this->getSetting('government_fee_start') !== null ? $this->getSetting('government_fee_start') : array(Model_Listing_Commercial::GOVERNMENT_FEE_MIN, Model_Listing_Commercial::GOVERNMENT_FEE_MAX),
                        'currency' => '$HKD',
                        'range'    => true,
                        'step'     => 500,
                        'change'   => 'refineSearch()',
                        ),
                    'label'       => 'government Fee (HKD)',
                    'decorators' => array(
                            'Errors',
                            'UiWidgetElement',
                            array('Label', array('escape' => false)),
                            array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'slide')),
                    )
                )
        );



        // -> Fit-Out Conditions
        $form1->addElement('select', 'fitoutconditions', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => Model_Listing_Commercial::getFitoutConditionsSearch(),
            'required'     => false,
            'label'        => 'Fit-Out Conditions',
            'value'        => $this->getSetting('fitoutconditions'),
        ));

        // -> View
        $form1->addElement('select', 'views', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => Model_Listing_Commercial::getViewsSearch(),
            'required'     => false,
            'label'        => 'View',
            'value'        => $this->getSetting('views'),
        ));

        // -> Toilet
        $form1->addElement('select', 'toilet', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => Model_Listing_Commercial::getToiletSearch(),
            'required'     => false,
            'label'        => 'Toilet',
            'value'        => $this->getSetting('toilet'),
        ));

        // -> Availability
        $form1->addElement('select', 'availability', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => Model_Listing_Commercial::getAvailabilitySearch(),
            'required'     => false,
            'label'        => 'Availability',
            'value'        => $this->getSetting('availability'),
        ));

        // -> Air Conditioning System
        $form1->addElement('select', 'airconsystem', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => Model_Listing_Commercial::getAirConditioningSystemSearch(),
            'required'     => false,
            'label'        => 'Air Conditioning System',
            'value'        => $this->getSetting('airconsystem'),
        ));

        $form1->addDecorator('fieldset', array('class' => 'optional', 'style' => 'display:none'));
        $form1->setLegend('Additional Features');
        $this->addSubForm($form1, 'optional');
    }

    protected function keySearchTools()
    {
        $form1 = $this->getNewSubForm();

        // --> Type
        $form1->addElement('select', 'type', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => Model_Listing_Commercial::getPropertyType(),
            'required'     => false,
            'label'        => 'Property Type',
            'value'        => $this->getSetting('type'),
        ));

        // --> Area
        $area = Model_Location::getAreaSearch();
        $selected_area = $this->getSetting('area');
        if (empty($selected_area)) {
            reset($area);
            $selected_area = key($area);
        }
        $form1->addElement('select', 'area', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => $area,
            'required'     => false,
            'label'        => 'Area',
            'value'        => $this->getSetting('area'),
        ));

        // --> District
        $form1->addElement('select', 'district', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'    => $this->elementSelectDecorators,
            'multiOptions'  => Model_Location::getAreaL2Search($selected_area),
            'required'      => false,
            'label'         => 'District',
            'value'         => $this->getSetting('district'),
        ));        

        // -> Price
        /*
        $form1->addElement('jqslider', 'price', array(
                    'jQueryParams' => array(
                        'min'      => $this->getSetting('price_min') !== null ? $this->getSetting('price_min') : 0,
                        'max'      => $this->getSetting('price_max') !== null ? $this->getSetting('price_max') : 150000,
                        'values'   => $this->getSetting('price_start') !== null ? $this->getSetting('price_start') : array('0', '150000'),
                        'currency' => '$HKD',
                        'range'    => true,
                        'step'     => 500,
                        ),
                    'label'       => 'Price (HKD$)',
                    'decorators' => array(
                            'Errors',
                            'UiWidgetElement',
                            array('Label', array('escape' => false)),
                            array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'slide')),
                    )
                )
        );
        */

        $form1->addElement('textRange', 'price', array(
                        'label'       => 'Price (HKD)',
                        'value'       => $this->getSetting('price_start') !== null ? $this->getSetting('price_start') : array(),
                        'class'       => array('class' => 'text-range'),
                        'decorators'  => array(
                                'Errors',
                                'ViewHelper',
                                array('Label', array('escape' => false)),
                                array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'text range')),
                        )
                    )
        );
        
        // -> Size
        $form1->addElement('jqslider', 'size', array(
                    'jQueryParams' => array(
                        'min'      => $this->getSetting('size_min') !== null ? $this->getSetting('size_min') : Model_Listing_Commercial::SIZE_MIN,
                        'max'      => $this->getSetting('size_max') !== null ? $this->getSetting('size_max') : Model_Listing_Commercial::SIZE_MAX,
                        'values'   => $this->getSetting('size_start') !== null ? $this->getSetting('size_start') : array(Model_Listing_Commercial::SIZE_MIN, Model_Listing_Commercial::SIZE_MAX),
                        'range'    => true,
                        //'step'     => 500,
                        'change'   => 'refineSearch()',
                        ),
                    'label'       => 'Size (sq.ft)',
                    'decorators' => array(
                            'Errors',
                            'UiWidgetElement',
                            array('Label', array('escape' => false)),
                            array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'slide')),
                    )
                )
        );
        
        // -> Building age
        $form1->addElement('jqslider', 'building_age', array(
                    'jQueryParams' => array(
                        'min'      => $this->getSetting('building_age_min') !== null ? $this->getSetting('building_age_min') : Model_Listing_Commercial::BUILDING_AGE_MIN,
                        'max'      => $this->getSetting('building_age_max') !== null ? $this->getSetting('building_age_max') : Model_Listing_Commercial::BUILDING_AGE_MAX,
                        'values'   => $this->getSetting('building_age_start') !== null ? $this->getSetting('building_age_start') : array(Model_Listing_Commercial::BUILDING_AGE_MIN, Model_Listing_Commercial::BUILDING_AGE_MAX),
                        'range'    => true,
                        //'step'     => 0.5,
                        'change'   => 'refineSearch()',
                        ),
                    'label'       => 'Building Age',
                    'decorators' => array(
                            'Errors',
                            'UiWidgetElement',
                            array('Label', array('escape' => false)),
                            array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'slide')),
                    )
                )
        );

        // -> Floor Zone
        $form1->addElement('select', 'floor_zone', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementSelectDecorators,
            'multiOptions' => Model_Listing_Commercial::getFloorZone(),
            'required'     => false,
            'label'        => 'Ground Floor',
            'value'        => $this->getSetting('floor_zone'),
        ));

        $form1->addElement('hidden', 'add_show', array(
            'value'       => $this->getSetting('add_show'),
            'id'          => 'add_show',
            'name'        => 'add_show',
        ));
        $form1->getElement('add_show')->removeDecorator('label');

        // --> Street
        $form1->addElement('text', 'street', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators' => $this->elementDecorators,
            'required'   => false,
            'label'      => 'Street/Building name',
            'value'      => $this->getSetting('street'),
        ));

        $form1->addDisplayGroup(array('street', 'v'), 'key_search_tool2',
            array(
                'decorators' => array_merge($this->displayGroupDecorators, array(array('HtmlTag', array('tag' => 'div', 'class' => 'text'))))
            )
        );

        // --> Additional Button
        $form1->addElement('hidden', 'additional_button', array(
            'decorators'  => array(
                    'Errors',
                    'ViewHelper',
                    array('Description', array('escape' => false, 'placement' => 'PREPEND', 'tag' => 'div', 'class' => 'desc more', 'id' => 'additional_btn')),
            ),
            'Description' => '<a href="#">Additional Features »</a>',
            'value'       => $this->getSetting('key_search_tool_district'),
        ));

        $form1->addDecorator('fieldset', array('class' => 'key_search'));
        $form1->setLegend('Key Search Tools');

        $this->addSubForm($form1, 'key_search_tools');
    }

    public function init()
    {
        parent::init();

        $this->setSubFormDecorators($this->subFormDecorators);
        $this->setDisplayGroupDecorators($this->displayGroupDecorators);

        $element = new Zend_Form_Element_Hidden('keyword');
        if (isset($_GET['keyword'])) {$element->setValue($_GET['keyword']);}
        $element->setDecorators(array(
                'ViewHelper'
            )
        );
        $this->addElement($element);

        $element = new Zend_Form_Element_Hidden('small_category_list');
        if (Zend_Registry::isRegistered('category_list_selected')) {
            $selected = Zend_Registry::get('category_list_selected');
            $element->setValue($selected);
        } elseif (!empty($_GET['small_category_list'])) {
            $selected = $_GET['small_category_list'];
            $element->setValue($selected);
        } elseif (Zend_Registry::isRegistered('category_list_id')) {
            $id = Zend_Registry::get('category_list_id');
            $cat = Model_Category::find($id);
            $this->view->category = $cat;
            if (empty($cat->customization)) {
                $get['small_category_list'] = $id;
            }
            else {
                $get['small_category_list'] = $cat->customization;
            }
            $selected = $get['small_category_list'];
            $element->setValue($selected);
        }
        $element->setDecorators(array(
                'ViewHelper'
            )
        );
        $this->addElement($element);

                
        //$this->narrowSearch();
        $this->wantTo();
        $this->keySearchTools();
        $this->optional();
        $this->button();
         
    }

    function populate(array $values)
    {
        if (isset($_GET['key_search_tools']['add_show'])) {
            $this->settings->add_show = $_GET['key_search_tools']['add_show'];
        }
        else {
            $this->settings->add_show = '0';
        }

        //Keywords
        if (isset($values['key_search_tools']['keyword'])) {
            $this->settings->keyword = $values['key_search_tools']['keyword'];
        }
        if (isset($_GET['keyword'])) {
            if (empty($values['key_search_tools']['keyword'])) {
                $this->settings->keyword = $_GET['keyword'];
            }
        }

        //I want to
        if (isset($values['want_to']['buy_rent'])) {
            $this->settings->buy_rent = $values['want_to']['buy_rent'];
        }
        else {
            $this->settings->buy_rent = 'Both';
        }
        if (isset($values['wantto_comm'])) {
            $this->settings->buy_rent = $values['wantto_comm'];
        }

        //Preferred Seller
        if (isset($values['seller']['saleby'])) {
            $this->settings->saleby = $values['seller']['saleby'];
        }
        if (isset($values['agency_owner_comm'])) {
            $this->settings->saleby = $values['agency_owner_comm'];
        }

        //Type
        if (isset($values['key_search_tools']['type'])) {
            $this->settings->type = $values['key_search_tools']['type'];
        }

        //Area
        if (isset($values['key_search_tools']['area'])) {
            $this->settings->area = $values['key_search_tools']['area'];
        }
        if (isset($values['area_comm'])) {
            $this->settings->area = $values['area_comm'];
        }

        //District
        if (isset($values['key_search_tools']['district'])) {
            $this->settings->district = $values['key_search_tools']['district'];
        }
        if (isset($values['district_comm'])) {
            $this->settings->district = $values['district_comm'];
        }
		 if (isset($values['district'])) {
            $this->settings->district = $values['district'];
        }
		
		if (!empty($_GET['keyword'])) {
			$loc = Model_Location::one(array('nm_en' => array('$regex' => $_GET['keyword'], '$options' => 'i' )));
			if (!empty($loc) && empty($this->settings->district) ) {
				$this->settings->district = $loc->_id;
			}
		}

        //Price
        if (isset($values['key_search_tools-price']) && isset($values['key_search_tools-price-1'])) {
            $this->settings->price_start = array($values['key_search_tools-price'], $values['key_search_tools-price-1']);
        }
        if (isset($values['price_comm']) && isset($values['price_comm-1'])) {
            $this->settings->price_start = array($values['price_comm'], $values['price_comm-1']);
        }

        //Management & government Fees
        if (isset($values['optional']['includes_fees'])) {
            $this->settings->includes_fees = $values['optional']['includes_fees'];
        } 

        //Management Fee
        if (isset($values['optional-management_fee']) && isset($values['optional-management_fee-1'])) {
            $this->settings->management_fee_start = array($values['optional-management_fee'], $values['optional-management_fee-1']);
        }

        //government Fee
        if (isset($values['optional-government_fee']) && isset($values['optional-government_fee-1'])) {
            $this->settings->government_fee_start = array($values['optional-government_fee'], $values['optional-government_fee-1']);
        }

        //Buy with lease
        if (isset($values['optional']['buy_with_lease'])) {
            $this->settings->buy_with_lease = $values['optional']['buy_with_lease'];
        }

        //Price Negotiable
        if (isset($values['optional']['price_negotiable'])) {
            $this->settings->price_negotiable = $values['optional']['price_negotiable'];
        }

        //Floor Zone
        if (isset($values['key_search_tools']['floor_zone'])) {
            $this->settings->floor_zone = $values['key_search_tools']['floor_zone'];
        }

        //Size
        if (isset($values['key_search_tools-size']) && isset($values['key_search_tools-size-1'])) {
            $this->settings->size_start = array($values['key_search_tools-size'], $values['key_search_tools-size-1']);
        }
        if (isset($values['size_comm']) && isset($values['size_comm-1'])) {
            $this->settings->size_start = array($values['size_comm'], $values['size_comm-1']);
        }

        //Building Age
        if (isset($values['key_search_tools-building_age']) && isset($values['key_search_tools-building_age-1'])) {
            $this->settings->building_age_start = array($values['key_search_tools-building_age'], $values['key_search_tools-building_age-1']);
        }
        if (isset($values['building_age_comm']) && isset($values['building_age_comm-1'])) {
            $this->settings->building_age_start = array($values['building_age_comm'], $values['building_age_comm-1']);
        }

        //Fit-Out Conditions
        if (isset($values['optional']['fitoutconditions'])) {
            $this->settings->fitoutconditions = $values['optional']['fitoutconditions'];
        }

        //View
        if (isset($values['optional']['views'])) {
            $this->settings->views = $values['optional']['views'];
        }

        //Toilet
        if (isset($values['optional']['toilet'])) {
            $this->settings->toilet = $values['optional']['toilet'];
        }

        //Availability
        if (isset($values['optional']['availability'])) {
            $this->settings->availability = $values['optional']['availability'];
        }

        //Air Conditioning System
        if (isset($values['optional']['airconsystem'])) {
            $this->settings->airconsystem = $values['optional']['airconsystem'];
        }
    }


    private function getNewSubForm()
    {
        $form = new Ac_SubForm();
        $form->setDecorators($this->subFormDecorators);
        $form->setDisplayGroupDecorators($this->displayGroupDecorators);
        return $form;
    }

    private function getSetting($name)
    {
        if (!empty($this->settings->$name)) {
            return $this->settings->$name;
        }
        return null;
    }

    public function __toString()
    {
        $str = '
            $j("#key_search_tools-area").change(function (event) {
                event.stopImmediatePropagation();
                $j.get("/search/get-attribute", { c:"area", f:"district_bis", id: $j("#key_search_tools-area").val() },
                    function(data) {
                        $j("#key_search_tools-district").empty();
                        $j.each(data, function (index, value) {
                            $(document.createElement("option"))
                                .html(value)
                                .attr("value", index)
                                .appendTo($("#key_search_tools-district"));
                        });
                    });
           });
        ';
        $this->view->JQuery()->addJavascript($str);
        return parent::__toString();
    }
}
